class Solution {
public:
    int maxProfit(vector<int>& prices) {
        int ret = 0, left = 0, sz = prices.size();
        while(left < sz)
        {
            int right = left + 1;
            while(right < sz && prices[right] > prices[right - 1])
            {
                ++right;
            }
            ret += prices[right - 1] - prices[left]; // right已经是极大值下一个了
            left = right;
        }
        return ret;
    }
};